//
//  GuiderIconView.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/7/2.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "GuiderIconView.h"

@interface GuiderIconView()

@property (nonatomic,strong)UIImageView * headerImageView;

@property (nonatomic,strong)UIImageView * certifyImageView;
@end

@implementation GuiderIconView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self createheaderImageViewWithFrame:self.bounds];
    [self createcertifyImageViewWithFrame:self.bounds];
    self.userInteractionEnabled = NO;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createheaderImageViewWithFrame:self.bounds];
        [self createcertifyImageViewWithFrame:self.bounds];
    }
    return self;
}


- (void)setBorderColor:(UIColor *)borderColor {
    _headerImageView.layer.borderColor = borderColor.CGColor;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self createheaderImageViewWithFrame:self.bounds];
        [self createcertifyImageViewWithFrame:self.bounds];
        
    }
    return self;
}
- (void)createheaderImageViewWithFrame:(CGRect)frame {
    
    _headerImageView = [[UIImageView alloc] initWithFrame:frame];
    _headerImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:_headerImageView];
    _headerImageView.image = [UIImage imageNamed:@"default"];
    _headerImageView.layer.cornerRadius = frame.size.height/2;
    _headerImageView.layer.borderWidth = 0.2;
    _headerImageView.layer.borderColor = kContentColor.CGColor;
    _headerImageView.clipsToBounds = YES;
}

- (void)createcertifyImageViewWithFrame:(CGRect)frame{
    
    if (frame.size.width <= 32) {
        _certifyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width - 12, frame.size.height - 12, 12, 12)];
    }else {
         _certifyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width - 17, frame.size.height - 17, 17, 17)];
    }
    _certifyImageView.layer.cornerRadius =  8.5;
    _certifyImageView.contentMode = UIViewContentModeScaleAspectFill;
    _certifyImageView.clipsToBounds = YES;
    _certifyImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    _certifyImageView.layer.borderWidth = 0.2;
    _certifyImageView.image = [UIImage imageNamed:@"认证"];
    _certifyImageView.hidden = YES;
    [self addSubview:_certifyImageView];
}


- (void)setHeaderImageName:(NSString *)headerImageName {
    [_headerImageView setImageURL:[NSURL URLWithString:headerImageName] placeholderImage:[UIImage imageNamed:@"default"]];
}

- (void)setVip:(NSInteger)vip {
    if (vip) {
        _certifyImageView.hidden = NO;
    }else {
        _certifyImageView.hidden = YES;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
